package com.classroom.smart.service;

import com.classroom.smart.dto.PageDTO;
import com.classroom.smart.mapper.CourseMapper;
import com.classroom.smart.pojo.Course;
import com.classroom.smart.pojo.CourseExample;
import com.classroom.smart.result.PageResult;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class CourseService {

    @Autowired
    private CourseMapper courseMapper;

    //根据条件分页查询老师列表
    public List<Course> viewCourseByQuery(int current, String query) {
        CourseExample courseExample = new CourseExample();
        CourseExample.Criteria criteria = courseExample.createCriteria();
        criteria.andNameLike("%" + query + "%");
        PageHelper.startPage(current,3);
        List<Course> list = courseMapper.selectByExample(courseExample);
        return list;
    }


    //删除操作
    public boolean delete(int courseId) {
        int i = courseMapper.deleteByPrimaryKey(courseId);
        return i>0?true:false;
    }

    //根据ID查询用户信息
    public Course viewOne(int courseId) {
        Course course = courseMapper.selectByPrimaryKey(courseId);
        return course;
    }

    //更新用户信息
    public boolean update(Course course){
        int i = courseMapper.updateByPrimaryKeySelective(course);
        return i>0?true:false;
    }

    //添加用户
    public boolean addOne(Course course){
        int i = courseMapper.insert(course);
        return i>0;
    }
}
